package springMVC.getParams.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Author quan
 * @Description 接收文件
 * @Date 2023/7/22 16:55
 */
@Slf4j
@RestController
@RequestMapping("/web")
public class Demo7_GetFile {
    @RequestMapping("/get7")
    //file1表示从前端获取到的文件名
    public String get7(@RequestPart("file1") MultipartFile file) throws IOException {
        log.info(file.getContentType());
        log.info(file.getOriginalFilename());
        //将文件保存到服务器上
        file.transferTo(new File("D:/AAQX/"+file.getOriginalFilename()));
        return "success";
    }
}
